package com.mlz.mlzmall.ui.activity.act.personal.NetworkRequest;

import android.content.Context;
import android.util.Log;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.mlz.mlzmall.ui.dialog.ReuestDialog;
import com.mlz.mlzmall.ui.utils.mlz.ConfigInfo;
import com.mlz.mlzmall.ui.utils.mlz.URL;
import com.mlz.mlzmall.ui.utils.util.ACache;
import com.mlz.mlzmall.ui.utils.util.SharedUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description 我的活动请求类
 * Created by 安帅 on 2016/5/27 17:55.
 * PackageName com.mlz.mlzmall.ui.activity.act.personal.NetworkRequest.
 * ProjectName mlzmall_android.
 */
public class MyActivityRequestUtils {
    private static final String TGA = "MyActivityRequestUtils";

    /**
     * 获取用户参加过的活动
     *
     * @param context
     * @param listener
     * @return
     */
    public static StringRequest getMLZActivityList(final Context context, Response.Listener<String> listener) {

        StringRequest request = new StringRequest(Request.Method.GET, URL.PROMOTION.MY_PROMOTION_NEW, listener, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ReuestDialog.dissmissProgressDialog();
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<>();
                headers.put(ConfigInfo.CHARSET, ConfigInfo.UTF8);
                headers.put(ConfigInfo.COOKIE, ConfigInfo.COOKIE_KEY + ACache.get(context).getAsString("sessionKeyLogin"));
                headers.put(ConfigInfo.TYPE, ConfigInfo.TYPE_KEY);
                Log.i(TGA, "我的活动完整头部：" + String.valueOf(headers));
                return headers;
            }
        };
        return request;
    }

    /**
     * 获取抽奖活动信息
     */
    public static JsonObjectRequest getMLZSweepStakes(final Context context, int promotionId, Response.Listener<JSONObject> listener) {
        JSONObject json = new JSONObject();
        try {
            json.put("promotionId", promotionId);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, URL.PROMOTION.MY_PROMOTION_CHOUJIANG + "?promotionId=" + promotionId, json, listener, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {

            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<>();
                headers.put(ConfigInfo.CHARSET, ConfigInfo.UTF8);
                headers.put(ConfigInfo.COOKIE, ConfigInfo.COOKIE_KEY + ACache.get(context).getAsString("sessionKeyLogin"));
                headers.put(ConfigInfo.TYPE, ConfigInfo.TYPE_KEY);
                Log.i(TGA, "我的活动抽奖完整头部：" + String.valueOf(headers));
                return headers;
            }

        };
        return request;
    }

    /**
     * 获取领奖动作
     *
     * @param context
     * @param type
     * @param addressId
     * @param promotionId
     * @param listener
     * @return
     */
    public static JsonObjectRequest getMLZToReceivePrizeAction(final Context context, int type, int addressId, int promotionId, Response.Listener<JSONObject> listener) {
        JSONObject json = new JSONObject();
        try {
            json.put("type", type);
            json.put("addressId", addressId);
            json.put("promotionId", promotionId);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        JsonObjectRequest request =
                new JsonObjectRequest(Request.Method.POST, URL.PROMOTION.MY_PROMOTION_CHOUJIANG_ACTION, json, listener, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {

                    }
                }) {
                    @Override
                    public Map<String, String> getHeaders() throws AuthFailureError {
                        HashMap<String, String> headers = new HashMap<>();
                        headers.put(ConfigInfo.CHARSET, ConfigInfo.UTF8);
                        headers.put(ConfigInfo.COOKIE, ConfigInfo.COOKIE_KEY + ACache.get(context).getAsString("sessionKeyLogin"));
                        headers.put(ConfigInfo.TYPE, ConfigInfo.TYPE_KEY);
                        Log.i(TGA, "我的活动抽奖动作完整头部：" + String.valueOf(headers));
                        return headers;
                    }
                };
        return request;
    }

    /**
     * 领奖视图
     *
     * @param context
     * @param promotionId
     * @param type
     * @param listener
     * @return
     */
    public static StringRequest getMLZAcceptTheView(final Context context, int promotionId, int type, Response.Listener<String> listener) {

        StringRequest request = new StringRequest(Request.Method.GET, URL.PROMOTION.MY_PROMOTION_CHOUJIANG_VIEW + "?promotionId=" + promotionId + "&type=" + type, listener, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {

            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<>();
                headers.put(ConfigInfo.CHARSET, ConfigInfo.UTF8);
                headers.put(ConfigInfo.COOKIE, ConfigInfo.COOKIE_KEY + ACache.get(context).getAsString("sessionKeyLogin"));
                headers.put(ConfigInfo.TYPE, ConfigInfo.TYPE_KEY);
                Log.i(TGA, "我的活动抽奖视图完整头部：" + String.valueOf(headers));
                return headers;
            }


        };
        return request;
    }

    /**
     * 获取分享活动
     *
     * @param context
     * @param promotionId
     * @param listener
     * @return
     */
    public static StringRequest getMLZShareRequset(final Context context, int promotionId, Response.Listener<String> listener) {
        StringRequest request = new StringRequest(Request.Method.GET, URL.PROMOTION.MY_PROMOTION_SHARE + "?promotionId=" + promotionId, listener, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {

            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<>();
                headers.put(ConfigInfo.CHARSET, ConfigInfo.UTF8);
                headers.put(ConfigInfo.COOKIE, ConfigInfo.COOKIE_KEY +ACache.get(context).getAsString("sessionKeyLogin"));
                headers.put(ConfigInfo.TYPE, ConfigInfo.TYPE_KEY);
                Log.i(TGA, "我的活动分享活动完整头部：" + String.valueOf(headers));
                return headers;
            }
        };
        return request;
    }
    /**
     * 获取分享信息回调
     */
    public static StringRequest getMLZShareReturnRequset(final Context context, int promotionId, Response.Listener<String> listener) {
        StringRequest request = new StringRequest(Request.Method.GET, URL.PROMOTION.MY_PROMOTION_SHARE_RETNRN + "?promotionId=" + promotionId, listener, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {

            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<>();
                headers.put(ConfigInfo.CHARSET, ConfigInfo.UTF8);
                headers.put(ConfigInfo.COOKIE, ConfigInfo.COOKIE_KEY + ACache.get(context).getAsString("sessionKeyLogin"));
                headers.put(ConfigInfo.TYPE, ConfigInfo.TYPE_KEY);
                Log.i(TGA, "我的活动分享活动完整头部：" + String.valueOf(headers));
                return headers;
            }
        };
        return request;
    }


}
